1 00:00:00,700 --> 00:00:08,110 Now that we have a wave loop, we can fire off things in the world periodically, like our volcano eruption. 2 00:00:08,290 --> 00:00:13,210 At certain points of time, we could have waves of monsters coming, things like that. 3 00:00:13,240 --> 00:00:14,400 That's pretty cool. 4 00:00:14,410 --> 00:00:17,040 Let's start out with a wave of monsters. 5 00:00:17,050 --> 00:00:20,980 I'll use the drooling zombies again until we have our own monsters. 6 00:00:20,980 --> 00:00:25,780 But this time, what I'm going to do is I'm going to control the location at which they spawn. 7 00:00:25,780 --> 00:00:30,790 So I'm going to add a part, and this is going to be a spawn location. 8 00:00:31,000 --> 00:00:35,380 I'm going to say Bon Logue. 9 00:00:35,440 --> 00:00:39,730 We can call it like an m spawn load for monster spawn. 10 00:00:39,730 --> 00:00:40,350 Luke. 11 00:00:40,360 --> 00:00:41,440 How's that? 12 00:00:41,620 --> 00:00:43,360 All right, now let's duplicate that. 13 00:00:43,360 --> 00:00:50,040 Collisions are off, so if I select it, control D, I duplicate in place and we'll do another one. 14 00:00:50,080 --> 00:00:53,860 Control D and another one control D. 15 00:00:54,040 --> 00:00:58,240 Obviously, you'd want to put these in different parts of your game, but this will be good. 16 00:00:58,240 --> 00:01:03,320 For example, like you might want to be in a room somewhere and have the zombies come out from all sides. 17 00:01:03,340 --> 00:01:04,760 That would be cool. 18 00:01:04,780 --> 00:01:05,230 All right. 19 00:01:05,230 --> 00:01:08,230 Let's go ahead and select all of our M spawn locks. 20 00:01:08,230 --> 00:01:11,380 So select the top shift, click the bottom, select some. 21 00:01:11,380 --> 00:01:15,880 All right, click and group as model or folder. 22 00:01:15,890 --> 00:01:16,690 They'll both work. 23 00:01:16,690 --> 00:01:18,820 They'll both work with no code changes. 24 00:01:19,450 --> 00:01:19,690 All right. 25 00:01:19,690 --> 00:01:26,110 I'm going to call this m spawn locks with an SX. 26 00:01:26,140 --> 00:01:27,610 Now I'm going to open that up. 27 00:01:27,610 --> 00:01:28,960 I'm going to change. 28 00:01:29,650 --> 00:01:33,490 Select the M spawn lock at the top shift, click the bottom. 29 00:01:33,490 --> 00:01:34,690 So they're all selected. 30 00:01:34,900 --> 00:01:36,070 I make these invisible. 31 00:01:36,070 --> 00:01:43,480 I don't want to see them transparency or change out to one and now I don't want to trip over them. 32 00:01:43,480 --> 00:01:46,210 So I'm going to go down and can Clyde turn that off? 33 00:01:46,570 --> 00:01:52,870 Since canned collides off, we don't want them to fall through the ground anchored on Cool. 34 00:01:52,870 --> 00:01:53,200 There we go. 35 00:01:53,200 --> 00:01:54,700 We got some spawn locations. 36 00:01:54,700 --> 00:02:04,270 Let's go over to our session utils and we'll start working on a function to spawn a wave of zombies. 37 00:02:04,270 --> 00:02:06,190 So I'll say local function. 38 00:02:06,580 --> 00:02:07,390 No local. 39 00:02:07,390 --> 00:02:13,750 I'm sorry, function window local utils spawn. 40 00:02:13,750 --> 00:02:24,160 I use a lowercase spawn zombies and I want the number of zombies to spawn number of zombies. 41 00:02:24,670 --> 00:02:25,330 Cool. 42 00:02:25,330 --> 00:02:31,270 Now I need to have a zombie to spawn and server storage, so I'm going to do it. 43 00:02:31,270 --> 00:02:33,220 So we have some in here already. 44 00:02:33,220 --> 00:02:35,260 We have our simple Z spanner. 45 00:02:36,060 --> 00:02:36,700 Right. 46 00:02:36,710 --> 00:02:44,150 I can just duplicate one of these control D and I'm going to drag it outside of my simple Z spinner. 47 00:02:44,630 --> 00:02:49,550 Like if I close that, it's going to be on the same level as my land, mine and my coin and my health 48 00:02:49,550 --> 00:02:50,090 pickup. 49 00:02:50,760 --> 00:02:52,800 All right, now I can get it easy. 50 00:02:53,450 --> 00:02:55,800 All right, so this is where this is unaffected. 51 00:02:55,800 --> 00:02:57,900 The simple Z spanner is unaffected. 52 00:02:58,590 --> 00:03:01,680 I want to get a reference to server storage. 53 00:03:01,680 --> 00:03:02,760 I'll call it SAS. 54 00:03:02,760 --> 00:03:04,790 That's my variable for server storage. 55 00:03:04,800 --> 00:03:11,760 So as SAS equals gain, get service server storage. 56 00:03:12,180 --> 00:03:21,690 I also want a random number generator to select my spawn location, so I'll do a local R and D. 57 00:03:21,690 --> 00:03:27,270 That's going to be my random number generator, random dot new. 58 00:03:27,270 --> 00:03:29,010 And here you can leave that blank. 59 00:03:29,010 --> 00:03:32,790 Or you could put this tick value. 60 00:03:32,790 --> 00:03:35,070 It's actually a seed value, right? 61 00:03:35,070 --> 00:03:40,350 You put a number in there that changes all the time and you get a different sequence of pseudo generated 62 00:03:40,350 --> 00:03:41,760 random numbers. 63 00:03:42,120 --> 00:03:46,110 All right, So now we're down here in the spawn Zombies. 64 00:03:46,110 --> 00:03:47,940 We have server storage. 65 00:03:47,940 --> 00:03:50,760 We need to get that template zombie to clone. 66 00:03:51,090 --> 00:03:54,960 So I'm going to say local t zombie for template. 67 00:03:54,960 --> 00:03:57,720 Zombie in server storage. 68 00:03:57,720 --> 00:04:00,750 Wait for child drooling zombie. 69 00:04:01,380 --> 00:04:02,070 There we go. 70 00:04:02,070 --> 00:04:06,840 It is this one right here, right under server storage. 71 00:04:06,840 --> 00:04:08,310 So we don't want to use that one. 72 00:04:08,310 --> 00:04:09,480 We want to clone it. 73 00:04:09,960 --> 00:04:10,140 Right. 74 00:04:10,290 --> 00:04:11,640 Just keep that one there. 75 00:04:11,910 --> 00:04:19,740 Also, I need to get a spawn array so I'll call a spawn array equals. 76 00:04:19,740 --> 00:04:28,950 Well, in our workspace we have our MN spawn locus and in there we have spawned locations and spawn 77 00:04:28,950 --> 00:04:31,050 locations for monster spawn. 78 00:04:31,290 --> 00:04:38,400 Let's do a get children that's going to get all of our all of our things that are underneath and spawn 79 00:04:38,400 --> 00:04:43,500 loops which happen to be spawn locations and we're going to store it in that array. 80 00:04:43,500 --> 00:04:47,400 It's a table, but we're storing it in an array like structure, right? 81 00:04:47,400 --> 00:04:49,320 There's no key value pair. 82 00:04:49,320 --> 00:04:52,740 It's just straight array of values. 83 00:04:53,490 --> 00:05:02,850 So I'm going to make a for loop for I and for I equals one to the number of zombies in steps of one 84 00:05:03,330 --> 00:05:06,240 do local. 85 00:05:06,240 --> 00:05:14,070 We will create a zombie by using the DT zom template and cloning it. 86 00:05:14,610 --> 00:05:18,390 Unlike Java, this is a deep clone, right? 87 00:05:18,390 --> 00:05:20,040 So it makes it exact copy. 88 00:05:21,080 --> 00:05:21,620 A Java. 89 00:05:21,620 --> 00:05:22,490 You have to override. 90 00:05:22,910 --> 00:05:25,400 You have have to override the method. 91 00:05:25,760 --> 00:05:26,090 All right. 92 00:05:26,090 --> 00:05:33,950 Now, our zombie parent needs to be the zombie needs to be in the workspace so you can make the parent 93 00:05:33,950 --> 00:05:37,490 the workspace or some child of the workspace. 94 00:05:37,490 --> 00:05:39,320 We'll just make it the workspace for now. 95 00:05:39,860 --> 00:05:40,160 All right. 96 00:05:40,160 --> 00:05:44,150 I'm going to need an index for my spawn location. 97 00:05:44,660 --> 00:05:50,390 This is an array, so we can access it with a number from 1 to 4 because there's four elements. 98 00:05:51,200 --> 00:05:54,070 I'll do the random number generator. 99 00:05:54,080 --> 00:06:04,760 I'll get the next integer, which is a random integer between one and then number of values in spawn 100 00:06:04,760 --> 00:06:05,360 array. 101 00:06:06,140 --> 00:06:06,470 Right? 102 00:06:06,470 --> 00:06:08,780 So this is like spawn array length. 103 00:06:08,780 --> 00:06:13,550 If you've done other languages that use the length function, this is the number of elements in this 104 00:06:13,550 --> 00:06:14,120 array. 105 00:06:14,120 --> 00:06:19,130 It doesn't work for key value pairs, but it does work if you're just have a table. 106 00:06:19,130 --> 00:06:20,520 It's a list like structure, right? 107 00:06:20,540 --> 00:06:21,890 Or an array like structure. 108 00:06:22,320 --> 00:06:25,640 Right now I'm going to get my zombie that I that I cloned. 109 00:06:25,670 --> 00:06:33,980 I'm going to move to my spawn arrays location. 110 00:06:33,980 --> 00:06:35,930 These are square brackets. 111 00:06:35,930 --> 00:06:40,520 Oh, I want index index dot possession. 112 00:06:41,840 --> 00:06:42,110 Right. 113 00:06:42,110 --> 00:06:45,530 So each one of these is one of the spawn locations in the array. 114 00:06:45,530 --> 00:06:45,890 Right? 115 00:06:45,890 --> 00:06:47,750 That's a number between one and four. 116 00:06:47,750 --> 00:06:49,160 We want the position. 117 00:06:49,160 --> 00:06:51,320 We're going to move to it now. 118 00:06:51,500 --> 00:06:57,860 It used to be that you had to have a primary part selected in your model if you wanted to use the move 119 00:06:57,860 --> 00:06:58,390 to. 120 00:06:58,400 --> 00:07:00,320 That's not the case anymore. 121 00:07:00,320 --> 00:07:05,230 But just for curiosity, go to your drooling zombie. 122 00:07:05,240 --> 00:07:06,440 Take a look here. 123 00:07:06,440 --> 00:07:07,730 Primary part. 124 00:07:07,730 --> 00:07:09,290 That's what you had to do. 125 00:07:09,290 --> 00:07:14,810 So usually the humanoid root parts, the primary part, you would select this. 126 00:07:16,470 --> 00:07:16,700 Then. 127 00:07:17,750 --> 00:07:19,280 You're not going to have any problems, though. 128 00:07:19,280 --> 00:07:20,840 They they made that easier. 129 00:07:20,840 --> 00:07:22,970 They made it more, more friendly. 130 00:07:23,420 --> 00:07:23,750 All right. 131 00:07:23,750 --> 00:07:25,190 Now I'm just going to do a weight. 132 00:07:26,570 --> 00:07:31,010 And that way we can see the zombie spawning from the different locations. 133 00:07:31,010 --> 00:07:31,370 Right. 134 00:07:31,370 --> 00:07:33,010 So it's going to loop through the number. 135 00:07:33,020 --> 00:07:35,930 Now, I just need to call this Where do I call it? 136 00:07:35,930 --> 00:07:37,820 I call it from my wave loop. 137 00:07:37,820 --> 00:07:41,270 I'm going to copy this, so don't spell it wrong. 138 00:07:41,270 --> 00:07:42,310 Copy. 139 00:07:42,320 --> 00:07:43,820 I'm going to go to my wave loop. 140 00:07:43,820 --> 00:07:46,910 Remember, it's in server script service, wave loop. 141 00:07:46,910 --> 00:07:48,980 But I also have it opened here. 142 00:07:49,310 --> 00:07:50,330 There we go. 143 00:07:50,600 --> 00:07:54,890 And in the wave loop, I'll just wait a second. 144 00:07:57,080 --> 00:07:58,490 And then spawned zombies. 145 00:07:58,520 --> 00:08:01,390 Oh, we don't have a number of zombies defined. 146 00:08:01,400 --> 00:08:03,680 Do a control C to copy that. 147 00:08:04,130 --> 00:08:05,930 Just make that a variable up here. 148 00:08:06,020 --> 00:08:09,500 Control V number of zombies and we'll make it five. 149 00:08:10,130 --> 00:08:11,330 All right, let's try it out. 150 00:08:11,330 --> 00:08:12,700 Let's see what we got. 151 00:08:12,710 --> 00:08:15,590 I think what I'm going to do. 152 00:08:16,400 --> 00:08:18,290 Is when I start the game. 153 00:08:18,980 --> 00:08:23,060 I'll just wait 5 seconds to get before we get the loop going. 154 00:08:23,430 --> 00:08:25,990 Right now, the way we can see things happen a little more. 155 00:08:26,000 --> 00:08:27,800 I want to do a play here. 156 00:08:28,540 --> 00:08:31,780 So I don't have to run all the way over from my teleporter. 157 00:08:33,340 --> 00:08:34,210 Here we go. 158 00:08:34,510 --> 00:08:37,150 And our locations are in here. 159 00:08:37,150 --> 00:08:38,310 So there we go. 160 00:08:38,320 --> 00:08:39,190 There's one. 161 00:08:40,450 --> 00:08:42,080 Two came out over there. 162 00:08:42,100 --> 00:08:43,180 There's one. 163 00:08:43,270 --> 00:08:44,190 There's one. 164 00:08:44,200 --> 00:08:48,400 So we're spawning zombies every 2 seconds. 165 00:08:48,400 --> 00:08:53,020 We make it through that loop, and then we spawn five of them, which takes 5 seconds. 166 00:08:53,020 --> 00:08:55,570 So that's why they're kind of coming out in that way. 167 00:08:55,570 --> 00:08:59,020 It doesn't really look like a wave yet, but we can fix that. 168 00:08:59,020 --> 00:09:00,430 They're going to keep coming. 169 00:09:00,460 --> 00:09:07,480 If you're curious of how many zombies you can get in the world, I believe it's still 255. 170 00:09:07,510 --> 00:09:11,020 It's the animations that run out first, right? 171 00:09:11,020 --> 00:09:13,750 So it's either like 255 or 256. 172 00:09:13,750 --> 00:09:16,360 It's like two to the eighth power for the animations. 173 00:09:16,630 --> 00:09:17,140 All right. 174 00:09:17,140 --> 00:09:19,090 So I will see you in the next video. 175 00:09:19,090 --> 00:09:23,260 We're going to start adding some more stuff to our wave loop.